其他
使用 PageHelper 插件分页查询很慢?一招帮你搞定!
耗时8个月联合打造 《 2023年Java高薪课程 》,已更新了 102G 视频,累计更新时长 500+ 个小时,需要的小伙伴可以了解下,一次购买,持续更新,无需2次付费。
1
描述2
原因select count(*) from ("原来的查询sql,相当于多查了一遍") user
SELECT count(0)
FROM (SELECT V.*,B.TypeName AS TravelTypeName
FROM (SELECT A.PKID, A.ApplyOrderNo FROM t1 AS A
LEFT JOIN t2 AS P
ON P.ApplyOrderNo = A.ApplyOrderNo
LEFT JOIN t3 AS T
ON A.UserCode = T.UserCode ) AS V
LEFT JOIN t4 AS B
ON V.TravelCode = B.TypeCode AND V.UserCode = B.UserCode AND B.Isdel = 0)
SELECT V.*,B.TypeName AS TravelTypeName
FROM (SELECT A.PKID, A.ApplyOrderNo FROM t1 AS A
LEFT JOIN t2 AS P
ON P.ApplyOrderNo = A.ApplyOrderNo
LEFT JOIN t3 AS T
ON A.UserCode = T.UserCode ) AS V
LEFT JOIN t4 AS B
ON V.TravelCode = B.TypeCode AND V.UserCode = B.UserCode AND B.Isdel = 0
3
优化方案Page<Map<String, Object>> getOrderInfo(Map<String, Integer> map);
Long getOrderInfo_COUNT();
<select id="getOrderInfo" resultType="Long" useCache="false">
SELECT V.*,B.TypeName AS TravelTypeName
FROM (SELECT A.PKID, A.ApplyOrderNo FROM t1 AS A
LEFT JOIN t2 AS P
ON P.ApplyOrderNo = A.ApplyOrderNo
LEFT JOIN t3 AS T
ON A.UserCode = T.UserCode ) AS V
LEFT JOIN t4 AS B
ON V.TravelCode = B.TypeCode AND V.UserCode = B.UserCode AND B.Isdel = 0
</select>
<select id="getOrderInfo_COUNT" resultType="Long" useCache="false">
SELECT
COUNT(1)
FROM t1
</select>
3
总结4
解决办法
【福利】2023 高薪课程,全面来袭(视频+笔记+源码)
【福利】2023 高薪课程,全面来袭(视频+笔记+源码)
往期推荐